/**
 * Created by Tim on 2017/5/23.
 */
$(function () {
    var add_btn=$("#add_btn");
    var back_btn=$("#back_btn");
    var name=$("#name");
    var company=$("#company");
    var address=$("#address");
    var wechatMerchantNum=$("#wechatMerchantNum");
    var wehcatAppID=$("#wehcatAppID");
    var lon=$("#lon");
    var lat=$("#lat");
    var wechatAPISecret=$("#wechatAPISecret");

    var add_distributor_form=$("#add_distributor_form");

    var pwd_btn=$("#pwd_btn");
    var password=$("#password");

    function PropertyMgr() {

    }

    PropertyMgr.prototype.Constructor = PropertyMgr;



    pwd_btn.on("click", function () {
        pwd_btn.css("display","none");
        password.attr("readonly",false);
        password.focus();
    });

    add_btn.on("click",function () {
        $(this).addClass("disabled");

        if (_isValid())
            add_distributor_form.submit();

        add_btn.removeClass("disabled");

    });

    back_btn.on("click",function () {
      window.history.go(-1);
    });


    function _isValid() {

        if (name.val()==''){
            name.focus();
            BootBox.warning("请输入名称！");
            return false;
        }
        if (company.val()==''){
            company.focus();
            BootBox.warning("请输入公司！");
            return false;
        }
        if (address.val()==''){
            address.focus();
            BootBox.warning("请输入地址！");
            return false;
        }
        if (lon.val()==''){
            lon.focus();
            BootBox.warning("请输入经度！");
            return false;
        }
        if (lat.val()==''){
            lat.focus();
            BootBox.warning("请输入纬度！");
            return false;
        }
        if (wechatMerchantNum.val()==''){
            wechatMerchantNum.focus();
            BootBox.warning("请输入微信商户号！");
            return false;
        }
        if (wehcatAppID.val()==''){
            wehcatAppID.focus();
            BootBox.warning("请输入微信公众账号AppId！");
            return false;
        }
        if (wechatAPISecret.val()==''){
            wechatAPISecret.focus();
            BootBox.warning("请输入商户平台API密钥！");
            return false;
        }
        return true;
    }

    window.PropertyMgr = new PropertyMgr();
});